# db-ticket.pm
# Copyright (C) 2006,2007  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#
package CCNCore::IPC::provision;
use strict; use warnings;
use base qw(CCNCore::Provision::Base);

sub run()
{
    my $self = shift;

    use CCNCore::IPC::Ticket;
    my $tickets_directory = $CCNCore::IPC::Ticket::_directory;
    my $tickets_name      = $CCNCore::IPC::Ticket::_name;

    use CCNCore::IPC::MessageStore;
    my $messages_directory = $CCNCore::IPC::MessageStore::_directory;
    my $messages_name      = $CCNCore::IPC::MessageStore::_name;

    if( $self->bootstrapping || $self->upgrading )
    {
        # Attempt to detect a broken database and recreate it if needed.
        CCN::Scripting::exec_command("/usr/bin/sqlite3 '$tickets_name' 'SELECT COUNT(pk) FROM tickets' > /dev/null || /bin/rm -f '$tickets_name'");
        # (Ideally we should purge the database at this point)
        # Force creation of the database if it does not exist.
        my $tickets = new CCNCore::IPC::Ticket;
    }

    # For Debian
    my $www_user  = 'www-data';
    my $www_group = 'www-data';

    # YYYPORT Other OSes?
    
    use CCNCore::Scripting;
    CCN::Scripting::exec_command(join(' ',
        CCNCore::Home::manager.'/lib/CCNCore/bin/local/clean-www.sh',
        qq('$www_user'), qq('$www_group'),
        qq('$tickets_directory'), qq('$tickets_name'),
        qq('$messages_directory'), qq('$messages_name'),
    ));

}

1;